<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Image_map extends CI_Controller { 

	

	public function __construct() {
		parent::__construct();
		$this->load->helper("assets_helper");
		$this->load->model("menu_model");
	}

	public function index(){
		$data = array(
			'slides' => $this->menu_model->get_all(),
		);
		$this->load->view('map/index' , $data);
	}
	
	public function image(){
		$this->load->helper("my_file_helper");
		$img = $this->input->get('img');
		$img_id = $this->input->get('id');
		list($width, $height) = getimagesize(IMAGE_PATH.$img);
		$data = array
			(	
				'img_id'		=> $img_id,
				'img_path' 		=> $img ,
				'img_width' 	=> $width,
				'img_height' 	=> $height,
				'slides' => $this->menu_model->get_all(),
			);
		$this->load->view("map/image_map" , $data);
	}
	public function save_map()
	{
		$data = json_decode($this->input->post('content') , true);
		if( json_last_error() !== JSON_ERROR_NONE ){
			 echo "error";
		}
		if(  count($data['coords']) === 0 ){
			echo "success";
			return;
		}
		
		$s = $this->menu_model->insert_img_coords($data['img_id'] , $data['coords']);
		
		if($s)
		{
			echo "success";
		}
		else{
			echo "error";
		}
		
	}
	
}